<template>
  <el-dialog
    :title="form.id?'编辑':'新增'"
    :visible.sync="dialogVisible"
    :before-close="close"
    width="30%"
  >
    <el-form label-width="120px">
      <el-form-item label="转接类型">
        <el-select v-model="form.transferType" size="mini" placeholder="请选择">
          <el-option
            v-for="(item,index) in typeList"
            :key="index"
            :label="item"
            :value="index"
          />
        </el-select>
      </el-form-item>
      <div class="titleStyle">
        <span>基本信息</span>
      </div>
      <el-form-item label="党员姓名">
        <el-input v-if="form.transferType===0" v-model="form.partyMemberName" size="mini" placeholder="请输入" />
        <el-select v-else filterable v-model="form.partyMemberId" >
          <el-option
            v-for="item in personList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="转入党组织">
        <el-input v-if="form.transferType===2" v-model="form.transferredToPartyOrgName" />
        <ClassifyTreeSelect v-else @input="getPartyId" @getValue="getPartyNode" :value="form.transferredToPartyOrgId" size="mini" />
      </el-form-item>
      <el-form-item label="党费缴至">
        <el-date-picker
          v-model="form.partyDuesPaidTo"
          size="mini"
          placeholder="请选择"
          type="month"
          value-format="yyyy-MM"
        />
      </el-form-item>
      <div class="titleStyle">
        <span>转接信息</span>
      </div>
      <el-form-item label="转出党支部全称">
        <el-input v-if="form.transferType!==2" v-model="form.transferredOutPartyOrgName" size="mini" placeholder="请输入" />
        <ClassifyTreeSelect v-else @input="getPartyId" @getValue="getOutPartyNode" :value="form.transferredOutPartyOrgId" size="mini" />
      </el-form-item>
      <el-form-item label="转出事由">
        <el-input
          v-model="form.reasonForTransfer"
          size="mini"
          placeholder="请输入"
          type="textarea"
          :rows="2"
        />
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirm">确 定</el-button>
      <el-button @click="close">取 消</el-button>
    </span>
  </el-dialog>
</template>
<script>
import ClassifyTreeSelect from '@/components/classifyTree/classifyTreeSelect.vue'
import { queryPersonList, add, edit } from '@/api/partyMemberManagement/transferManagement'
export default {
  components: {
    ClassifyTreeSelect
  },
  data () {
    return {
      dialogVisible: false,
      form: {},
      typeList: ['转入', '转出至系统内其他党组织', '转出至系统外党组织'],
      personList: []
    }
  },
  methods: {
    open (row) {
      this.getPersonList()
      this.form = { ...row }
      this.dialogVisible = true
    },
    confirm () {
      let submitForm = add
      if (this.form.id) {
        submitForm = edit
      }
      submitForm(this.form).then((res) => {
        this.$message.success('保存成功')
        this.$emit('getData')
        this.close()
      })
    },
    close () {
      this.form = {}
      this.dialogVisible = false
    },
    getPartyNode (node) {
      this.form.transferredToPartyOrgId = node?.id || null
      this.form.transferredToPartyOrgName = node?.fullNamePartyOrg || null
    },
    getOutPartyNode (node) {
      this.form.transferredOutPartyOrgId = node?.id || null
      this.form.transferredOutPartyOrgName = node?.fullNamePartyOrg || null
    },
    getPersonList () {
      queryPersonList().then((res) => {
        this.personList = res?.data || []
      })
    },
    getPartyId (id) {
      // console.log('id', id)
    }
  }
}
</script>
<style lang="scss" scoped>
  .titleStyle {
    font-weight: 600;
    height: 35px;
    line-height: 35px;
    padding-left: 10px;
    padding-right: 10px;
    margin-bottom: 8px;
    background-color: #d8eff9;
    display: flex;
    justify-content: space-between;
  }
</style>
